//
//  AEHomePageSubViewCell.m
//  AESOLAR_IOS
//
//  Created by Bin Tang on 2024/10/18.
//  Copyright © 2024 Mr.Wang. All rights reserved.
//

#import "AEHomePageSubViewCell.h"
#import "AE_Solar-Swift.h"

@interface AEHomePageSubViewCell ()

/// 分享按钮
@property (nonatomic, strong) TYZImageTitleButton *btnShare;

/// 标题
@property (nonatomic, strong) UILabel *titleLabel;

/// 日期图标
@property (nonatomic, strong) UIImageView *dateTagImgView;

/// 时间
@property (nonatomic, strong) UILabel *datetimeLabel;



/// 日期图标
- (void)initWithDateTagImgView;

/// 时间
- (void)initWithDatetimeLabel;

@end

@implementation AEHomePageSubViewCell

- (void)initWithSubViewCell {
    [super initWithSubViewCell];
    
    self.contentView.backgroundColor = kWhiteColor;
    
    CGRect frame = CGRectMake(15, 0, kScreenW - 15 * 2, 1);
    [CALayer drawLine:self.contentView frame:frame lineColor:[UIColor colorWithHexString:@"#EBEBEB"]];
    
    [self initWithBtnShare];
}

/// 分享
- (void)initWithBtnShare {
    if (!_btnShare) {
        UIImage *image = [UIImage imageNamed:@"ic_main_share"];
        UIFont *font = [UIFont systemFontOfSize:12 weight:UIFontWeightBold];
        NSString *title = [AEStringExten localizedValueWithKey:@"分享"];
        float width = [title widthForFont:font] + 2 + 5 + 16 + image.size.width;
        CGRect frame = CGRectMake(kScreenW - width - 15, 17, width, 23);
        _btnShare = [TYZImageTitleButton createWithImageButton:self.contentView frame:frame font:font target:self action:@selector(actionWithShare:) propertiesBlock:^(TYZImageTitleButton * _Nonnull button) {
            [button setTitle:title forState:UIControlStateNormal];
            [button setTitleColor:kThemeColor forState:UIControlStateNormal];
            [button setImage:image forState:UIControlStateNormal];
            [button layoutButtonWithEdgeInsetsStyle:TYZButtonEdgeInsetsStyleLeft imageTitleSpace:4];
            button.backgroundColor = [UIColor colorWithHexString:@"#EEEEEE"];
            button.layer.cornerRadius = frame.size.height * 0.5;
            button.layer.masksToBounds = YES;
        }];
    }
}

/// 标题
- (void)initWithTitleLabel {
    if (!_titleLabel) {
        CGRect frame = CGRectMake(15, 16, self.btnShare.left - 15 - 10, 22);
        _titleLabel = [UILabel createWithLabel:self.contentView frame:frame font:[UIFont systemFontOfSize:16 weight:UIFontWeightBold] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#3D444D"];
            label.text = @"二维若无若温热无若温热无若温热无若温热无若热污染我认为热污染温热无若";
        }];
    }
}

/// 日期图标
- (void)initWithDateTagImgView {
    if (!_dateTagImgView) {
        UIImage *image = [UIImage imageNamed:@"ic_main_date_tag"];
        CGRect frame = CGRectMake(15, _titleLabel.bottom + 6, image.size.width, image.size.height);
        _dateTagImgView = [UIImageView createWithImageView:self.contentView frame:frame defaultImage:image propertiesBlock:^(UIImageView * _Nonnull imageView) {
            
        }];
    }
}

/// 时间
- (void)initWithDatetimeLabel {
    if (!_datetimeLabel) {
        CGRect frame = CGRectMake(self.dateTagImgView.right + 4, 0, kScreenW - self.dateTagImgView.right - 4 - 20, 16);
        _datetimeLabel = [UILabel createWithLabel:self.contentView frame:frame font:[UIFont systemFontOfSize:12 weight:UIFontWeightRegular] propertiesBlock:^(UILabel * _Nonnull label) {
            label.textColor = [UIColor colorWithHexString:@"#8C9197"];
            label.text = @"2024-10-12 23:34:23";
        }];
        _datetimeLabel.centerY = self.dateTagImgView.centerY;
    }
}

/// 分享
/// - Parameter sender: sender description
- (void)actionWithShare:(id)sender {
    
}


- (void)updateCellData:(id)cellEntity {
    
    [self initWithTitleLabel];
    
    /// 日期图标
    [self initWithDateTagImgView];

    /// 时间
    [self initWithDatetimeLabel];

}

@end
